package cn.com.wxd.action.component.ueditor;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baidu.ueditor.ActionEnter;

/**
 * Title: 重写了Ueditor的Controller.jsp的功能
 * Description:重写了Ueditor的Controller.jsp的功能
 *
 * Company: Amumu管理平台
 * Copyright: Copyright (c) 2017
 * All right reserved.
 * Created by ComXu on 2017/5/10.
 *
 * @author WangXuDong
 * @version 1.0
 */
@Controller
@RequestMapping("/component/ueditor")
public class UeditroServerCtl {
    private static final Logger log = LoggerFactory.getLogger(UeditroServerCtl.class);
    @RequestMapping("/controller")
    public void controller(HttpServletRequest request, HttpServletResponse response){
        response.setContentType("application/json");
        String rootPath = request.getSession()
                .getServletContext().getRealPath("/");

        try {
            String exec = new ActionEnter(request, rootPath).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            log.error("Ueditor插件文件上传错误!", e);
        }
    }
}
